home *** CD-ROM | disk | FTP | other *** search
- var WisestampSignatureFactory =
- {
- lastInserted: null,
- _prefs: null,
-
- PREFIX: "<!--WISESTAMP_SIG_START-->",
- SUFFIX: "<!--WISESTAMP_SIG_END-->",
-
- //URL_PREFIX: WiseStampComm.HOST + "/link?site=",
-
- get prefs() {
- if (!this._prefs) {
- this._prefs = Components.classes["@mozilla.org/preferences-service;1"].
- getService(Components.interfaces.nsIPrefService);
- this._prefs = this._prefs.getBranch("extensions.wisestamp.");
- }
- return this._prefs;
- },
-
- strings: Components.classes["@mozilla.org/intl/stringbundle;1"].getService(Components.interfaces.nsIStringBundleService).createBundle("chrome://wisestamp/locale/wisestamp.properties"),
-
- insertSignature: function (aType, doc)
- {
- WiseStampUtils.log("[signatureFactory.js::insertSignature] >>>>> ");
-
- var win = doc.defaultView;
- var body = doc.body;
- doc.execCommand("inserthtml", false, this.getFullSignatureHTML(aType));
- },
-
- getFullSignatureHTML: function getFullSignatureHTML_name(aType, aData)
- {
- var sig = this.PREFIX + this.createSignature(aData, aType) + this.SUFFIX;
- return sig;
- },
-
- // Call stack code
- showCallStack: function(){
- var f=this.showCallStack,result="Call stack:\n\n";
- //alert(f.name);
- //alert(f.arguments.callee);
- while((f=f.caller)!==null)
- {
- var match = f.toString().match(/function \w*\(([\w,\s]*)\)/);
- if (match == null)
- match = f.toString().match(/\w*: function (\w*)/);
-
- if (match == null)
- {
- alert("match == null: " + f.toString());
- break;
- }
-
- result += "F:" + match[0] + "\n";
- result += "A:" + this.parseArguments(f.arguments) + "\n";
- result += "\n";
- }
- alert(result);
- },
-
- parseArguments: function(a){
- var result=[];
-
- for(var i=0; i<a.length; i++){
- if ('string' == typeof a[i])
- result.push("\"" + a[i] + "\"");
- else
- result.push(a[i]);
- }
-
- return "(" + result.join(", ") + ")";
- },
-
- createSignature: function createSignature_name(data, aType)
- {
- WiseStampUtils.log("[signatureFactory.js::createSignature] >>>>> ");
-
- if (aType)
- type = aType;
- else
- type = data ? "custom" : this.prefs.getCharPref("type");
-
- this.lastInserted = type;
-
- if (type != "" && type != "none")
- {
- var sig = new WiseStampSignature(type, data);
- var html = sig.text;
- var str = "<div>" + html + "</div>";
-
- var im = this.getImHtml(sig);
- var services = this.getServicesHtml(sig);
- var advanced = sig.advanced;
- var feed = this.getRssHtml(sig, aType);
-
- if (html == "" && im == "" && services == "" && advanced == "")
- return "";
- else
- str += im + services;
-
- if (feed != "")
- str += "<div style='color: gray; font-size: 13.3px; padding-bottom: 5px;'>" + feed + "</div>";
-
- if (advanced != "")
- str += "<div>" + advanced + "</div>";
-
- if (type != "custom." && sig.promote)
- {
- var footer = WisestampGetAppObject().getFooter(this.strings);
- footer = this.wrapLinks(footer);
- str += footer;
- }
-
- str = "<div dir='" + sig.dir + "'>" + str + "</div>";
- //str = this.wrapLinks(str);
- return "<span style='color: black'>"+str+"</span>";
-
- } else
- return "";
- },
-
- getRssHtml: function(sig, aType)
- {
- var rss_title = sig.rss_title;
- var rss_url = sig.rss_url;
- var str = "";
-
- WiseStampUtils.log("[signatureFactory.js::getRssHtml] rss title = " + rss_title + ", rss url = " + rss_url);
-
- if (rss_url != "")
- {
- if (!this.feedBlog)
- {
- this.feedBlog = new WiseStampFeedWrapper(new WiseStampRSSFeed(rss_url), new WiseStampPostFormatter());
- this.rss_refreshed = false;
- }
-
- if (this.feedBlog._feed.url != rss_url)
- {
- this.feedBlog = new WiseStampFeedWrapper(new WiseStampRSSFeed(rss_url), new WiseStampPostFormatter());
- this.rss_refreshed = false;
- }
-
- if (!this.rss_refreshed)
- {
- try {
- this.feedBlog.refreshCache(
- function(){
- setTimeout(function() {
- WisestampSignatureFactory.rss_refreshed = true;
- WisestampGetAppObject().updateSiteFromChrome(aType);
- }, 0);
- });
- }
- catch (e){
- return "";
- }
-
- } else
- {
- if (this.feedBlog.format())
- {
- str +=
- rss_title + " " +
- "<span style='color: blue; text-decoration: underline;'>" +
- this.getLink(this.feedBlog.getLatestPost().getLink(), this.feedBlog.getLatestPost().getTitle())+
- "</span>";
- }
-
- this.rss_refreshed = false;
- }
- }
- return str;
- },
-
- getImHtml: function(sig) {
- var ims = sig.im.visible;
- if (ims.length > 0)
- {
- var imsrow = "";
- var counts = {};
-
- ims.forEach(function(aIM)
- {
- var value = "";
- if (aIM && aIM.length > 0)
- {
- if (aIM in counts)
- counts[aIM]++;
- else
- counts[aIM] = 0;
-
- if (sig.hasService(aIM, counts[aIM]))
- value = sig.getService(aIM, counts[aIM]);
-
- if (value.length > 0)
- {
- var name = this.strings.GetStringFromName(aIM);
- var label = '<font style="color: gray; font-weight: bold; font-size: 9pt;">' + name + ": " + '</font>';
- var valueText = '<font style="vertical-align: middle;">' + value + '</font>';
- var alt = "";
- var src = "http://www.images.wisestamp.com/" + aIM + ".png";
- var img = '<img src="' + src + '" width="16" height="16" style="vertical-align: middle; padding-right: 5px" alt="{alttext}"/>';
- var im = "";
-
- if (sig.im.showLabels && !sig.im.showIcons)
- im = label + value;
- else if (sig.im.showIcons && !sig.im.showLabels)
- im = img.replace("{alttext}", name + ": ") + " " + valueText;
- else
- im = img.replace("{alttext}", "") + label + valueText;
-
- if (imsrow != "")
- imsrow += " " + im;
- else
- imsrow = im;
- }
- }
- },
- this);
-
- if (imsrow != "")
- {
- var align = sig.dir == "rtl" ? "text-align: right;": "";
- var imprefix = sig.im.title;
- var prefix = sig.im.hideTitle ? "" : '<span style="color: gray;">' + imprefix + "</span>" + " ";
-
- return "<div style='padding: 10px 0 5px 0; font-family: arial,sans-serif;font-size: 13.3px;" + align + "'>" + prefix + imsrow + "</div>";
- }
- }
- return "";
- },
-
- getServicesHtml: function(sig)
- {
- var services = sig.services.visible;
- if (services.length > 0)
- {
- var servicerow = "", counts = {};
-
- services.forEach(function(service)
- {
- if (service && service.length > 0)
- {
- var value = "";
- if (service in counts)
- counts[service]++;
- else
- counts[service] = 0;
-
- if (sig.hasService(service, counts[service]))
- value = sig.getService(service, counts[service]);
-
- if (value.length > 0)
- {
- var url = value, imghtml = "", icon, alt = "", style = "";
- var serviceName = this.strings.GetStringFromName(service);
-
- if (!sig.services.showLabels)
- {
- alt = ' alt="' + serviceName + '" ';
- style = ' style="vertical-align: middle; padding-bottom: 5px;" ';
-
- } else
- style = ' style="padding-right: 3px; padding-bottom: 5px; vertical-align: middle" ';
-
- if (sig.services.showIcons)
- {
- icon = "http://www.images.wisestamp.com/" + service + ".png";
- imghtml += '<img src="' + icon + '" ' + alt + style + ' border="0" width="16" height="16"/>';
- }
-
- if (sig.services.showLabels)
- imghtml += "<span style='color: blue; font-size: 10pt; text-decoration: underline;'>" + serviceName + "</span>";
-
- //var html = '<a style="padding: 0 2px 0 2px;" href="' + url + '" target="_service" style="color: blue; font-size: 10pt">' + imghtml + '</a>';
-
- var html = this.getLink(url,imghtml,
- 'style="padding: 0 2px 0 2px; color: blue; font-size: 10pt; target="_service"');
-
- servicerow += html;
- }
- }
- },
- this);
-
- if (servicerow != "")
- {
- var align = sig.dir == "rtl" ? "text-align: right;": "";
- var serviceprefix = sig.services.title;
- var prefix = sig.services.hideTitle ? "" : '<span style="color: gray;">' + serviceprefix + "</span>" + " ";
- return "<div style='padding: 5px 0 5px 0; font-family: arial,sans-serif;font-size: 13.3px;" + align + "'>" + prefix + servicerow + "</div>";
- }
- }
- return "";
- },
-
- getLink: function(url,text,params)
- {
- if (WiseStampComm.loadSettings('wrap_links') == 1)
- {
- if (url.slice(0,7) == 'http://')
- url = url.slice(7);
-
- url = WiseStampComm.HOST + "/link?u=" + WiseStampUtils.getUserCode() + "&site=" + url;
- }
-
- return '<a href="'+url+'" '+params+'>'+text+'</a>';
- },
-
- wrapLinks: function(html)
- {
- var prefix = WiseStampComm.HOST + "/link?u=" + WiseStampUtils.getUserCode() + "&site=";
- return html.replace(/(href="http:\/\/)/g,"href=\""+prefix);
- //html = html.replace(/href="http://(.+?)\"/,"http://$1\"");
- }
- }
-
- function WiseStampSignature(type, aData)
- {
- this.type = this.im.type = this.services.type = type;
-
- if (type == "custom")
- {
- this.data = this.im.data = this.services.data = aData.data;
- this.settings = this.im.settings = this.services.settings = aData.settings;
-
- } else
- {
- var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService);
- this.prefs = prefs.getBranch("extensions.wisestamp.");
- this.branch = prefs.getBranch("extensions.wisestamp." + type + ".");
- this.im.branch = prefs.getBranch("extensions.wisestamp." + type + ".im");
- this.services.branch = prefs.getBranch("extensions.wisestamp." + type + ".services");
- }
- }
-
- WiseStampSignature.prototype = {
- branch: null,
-
- get text() {
- if (this.branch)
- return this.branch.getComplexValue("text", Components.interfaces.nsISupportsString).data;
- else
- return this.data.text;
- },
-
- get dir() {
- if (this.branch)
- return this.branch.getCharPref("dir");
- else
- return this.data.dir;
- },
-
- get advanced() {
- if (this.branch)
- return this.branch.getComplexValue("advanced", Components.interfaces.nsISupportsString).data;
- else
- return this.data.advanced;
- },
-
- get rss_title() {
- if (this.branch)
- return this.branch.getComplexValue("rss-title", Components.interfaces.nsISupportsString).data;
- else
- return this.data.rsstitle;
- },
-
- get rss_url() {
- if (this.branch)
- return this.branch.getComplexValue("rss-url", Components.interfaces.nsISupportsString).data;
- else
- return this.data.rssurl;
- },
-
- im: {
- get showLabels() {
- if (this.branch)
- return WiseStampPrefs.getBoolPref(this.type+".im.showLabels",true,"im.text");
- else
- return this.data.imFormat.showLabels;
- },
- get showIcons() {
- if (this.branch)
- return WiseStampPrefs.getBoolPref(this.type+".im.showIcons",true,"im.icons");
- else
- return this.data.imFormat.showIcons;
- },
- get hideTitle() {
- if (this.branch)
- return WiseStampPrefs.getBoolPref(this.type+".im.hideTitle",false,"hidechat");
- else
- return this.data.imFormat.hideTitle;
- },
- get title() {
- if (this.branch)
- return WiseStampPrefs.getComplexPref(this.type+".im.title",null,"chat");
- else
- return this.data.imFormat.title;
- },
- get visible() {
- if (this.branch)
- return this.branch.getCharPref("").split(",");
- else
- return this.data.show.im.split(",");
- }
- },
-
- services: {
- get showLabels() {
- if (this.branch)
- return WiseStampPrefs.getBoolPref(this.type+".services.showLabels",false,"services.text");
- else
- return this.data.servicesFormat.showLabels;
- },
- get showIcons() {
- if (this.branch)
- return WiseStampPrefs.getBoolPref(this.type+".services.showIcons",true,"services.icons");
- else
- return this.data.servicesFormat.showIcons;
- },
- get hideTitle() {
- if (this.branch)
- return WiseStampPrefs.getBoolPref(this.type+".services.hideTitle",false,"hidecontactme");
- else
- return this.data.servicesFormat.hideTitle;
- },
- get title() {
- if (this.branch)
- return WiseStampPrefs.getComplexPref(this.type+".services.title",null,"contactme");
- else
- return this.data.servicesFormat.title;
- },
- get visible() {
- if (this.branch)
- return this.branch.getCharPref("").split(",");
- else
- return this.data.show.services.split(",");
- }
- },
-
- hasService: function(aData) {
- if (this.branch)
- return this.branch.prefHasUserValue(aData);
- else
- return ((aData in this.data.im && this.data.im[aData].length > 0) || (aData in this.data.services && this.data.services[aData].length > 0))
- },
-
- getService: function(aData, count)
- {
- if (this.branch)
- return this.branch.getCharPref(aData).split("\r\n")[count];
- else if (aData in this.data.im)
- return this.data.im[aData][count];
- else if (aData in this.data.services)
- return this.data.services[aData][count];
- else
- return null;
- },
-
- get promote() {
- if (this.branch)
- return this.prefs.getBoolPref("promote");
- else
- return this.settings.promote;
- }
- }
-